﻿
using System;
using System.Windows;
using System.Windows.Controls;

namespace Red.Controls
{

    /// <summary>
    /// Facade "wraps" a single UI element so that it fills up it's entire facade's space. The wrapped
    /// element is exposed to a derived class via Element property. Allows to create an element that
    /// looks and behaves like, for example, a Grid, without exposing the whole public Grid interface,
    /// which improves encapsulation. Also, allows to put named elements inside such created UserControl
    /// </summary>
    /// <typeparam name="T">The FrameworkElement-derived type to wrap</typeparam>
    public class ElementFacade<T> : ContentControl
        where T : FrameworkElement, new()
    {
        #region Data

        private readonly T _element = new T();

        #endregion Data

        #region Properties

        protected T Element 
        { 
            get { return _element; } 
        }

        #endregion Properties

        #region C-tor
        
        public ElementFacade()
        {
            IsTabStop = false;
        }
        
        #endregion C-tor

        #region Protected methods

        protected override void OnInitialized( EventArgs e )
        {
            base.OnInitialized( e );
            AddChild( _element );
        }

        #endregion Protected methods
    }

}